﻿namespace Chain.BLL
{
    using Chain.DAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class SmsLog
    {
        private readonly Chain.DAL.SmsLog dal = new Chain.DAL.SmsLog();

        public int Add(Chain.Model.SmsLog model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.SmsLog> DataTableToList(DataTable dt)
        {
            List<Chain.Model.SmsLog> list = new List<Chain.Model.SmsLog>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.SmsLog item = new Chain.Model.SmsLog();
                    if ((dt.Rows[i]["SmsID"] != null) && (dt.Rows[i]["SmsID"].ToString() != ""))
                    {
                        item.SmsID = int.Parse(dt.Rows[i]["SmsID"].ToString());
                    }
                    if ((dt.Rows[i]["SmsMemID"] != null) && (dt.Rows[i]["SmsMemID"].ToString() != ""))
                    {
                        item.SmsMemID = int.Parse(dt.Rows[i]["SmsMemID"].ToString());
                    }
                    if ((dt.Rows[i]["SmsMobile"] != null) && (dt.Rows[i]["SmsMobile"].ToString() != ""))
                    {
                        item.SmsMobile = dt.Rows[i]["SmsMobile"].ToString();
                    }
                    if ((dt.Rows[i]["SmsContent"] != null) && (dt.Rows[i]["SmsContent"].ToString() != ""))
                    {
                        item.SmsContent = dt.Rows[i]["SmsContent"].ToString();
                    }
                    if ((dt.Rows[i]["SmsShopID"] != null) && (dt.Rows[i]["SmsShopID"].ToString() != ""))
                    {
                        item.SmsShopID = int.Parse(dt.Rows[i]["SmsShopID"].ToString());
                    }
                    if ((dt.Rows[i]["SmsTime"] != null) && (dt.Rows[i]["SmsTime"].ToString() != ""))
                    {
                        item.SmsTime = DateTime.Parse(dt.Rows[i]["SmsTime"].ToString());
                    }
                    if ((dt.Rows[i]["SmsUserID"] != null) && (dt.Rows[i]["SmsUserID"].ToString() != ""))
                    {
                        item.SmsUserID = int.Parse(dt.Rows[i]["SmsUserID"].ToString());
                    }
                    if ((dt.Rows[0]["SmsAmount"] != null) && (dt.Rows[0]["SmsAmount"].ToString() != ""))
                    {
                        item.SmsAmount = int.Parse(dt.Rows[0]["SmsAmount"].ToString());
                    }
                    if ((dt.Rows[0]["SmsAllAmount"] != null) && (dt.Rows[0]["SmsAllAmount"].ToString() != ""))
                    {
                        item.SmsAllAmount = int.Parse(dt.Rows[0]["SmsAllAmount"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int SmsID)
        {
            return this.dal.Delete(SmsID);
        }

        public bool DeleteList(string SmsIDlist)
        {
            return this.dal.DeleteList(SmsIDlist);
        }

        public bool Exists(int SmsID)
        {
            return this.dal.Exists(SmsID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.SmsLog GetModel(int SmsID)
        {
            return this.dal.GetModel(SmsID);
        }

        public List<Chain.Model.SmsLog> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public int GetSmsMonthNumber(string strWhere)
        {
            return this.dal.GetSmsMonthNumber(strWhere);
        }

        public DataSet GetSmsShopReport(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetSmsShopReport(PageSize, PageIndex, out resCount, strWhere);
        }

        public DataSet GetSmsShopReportDetail(string strShopID)
        {
            return this.dal.GetSmsShopReportDetail(strShopID);
        }

        public int GetSmsTotalNumber(string strWhere)
        {
            return this.dal.GetSmsTotalNumber(strWhere);
        }

        public bool Update(Chain.Model.SmsLog model)
        {
            return this.dal.Update(model);
        }
    }
}

